﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Microsoft.Samples.Office.UnifiedCommunications.Gadget.Events;
using Microsoft.Samples.Office.UnifiedCommunications.Gadget.EWSUtility;

namespace Microsoft.Samples.Office.UnifiedCommunications.Gadget
{
    public partial class SettingsFrame : Page
    {
        public SettingsFrame()
        {
            InitializeComponent();

            this.Unloaded += new RoutedEventHandler(SettingsFrame_Unloaded);

            GadgetEventManager.Instance.EWSConfiguredEvent += new EventHandler(Instance_EWSConfiguredEvent);
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ToggleRadioButtons(EWSConfiguration.IsEWSConfigured());

            txtName.Text = Gadget.DisplayName;
        }

        void SettingsFrame_Unloaded(object sender, RoutedEventArgs e)
        {
            GadgetEventManager.Instance.EWSConfiguredEvent -= new EventHandler(Instance_EWSConfiguredEvent);
        }

        void Instance_EWSConfiguredEvent(object sender, EventArgs e)
        {
            ToggleRadioButtons(true);
        }

        void ToggleRadioButtons(bool enabled)
        {
            rbEWS.IsEnabled = enabled;
            rbFav5.IsEnabled = enabled;
            rbTop5.IsEnabled = enabled;
            rbDesktopContacts.IsEnabled = enabled;
            rbVersion.IsEnabled = enabled;
        }

        void RadioButton_Connect_Click(object sender, RoutedEventArgs e)
        {
            RadioButton rb = e.Source as RadioButton;

            switch (rb.Content.ToString())
            {
                case "EWS":
                    this.PageFrame.Navigate(new Uri("EWSConfig.xaml", UriKind.Relative));
                    break;
                case "Top 5":
                    this.PageFrame.Navigate(new Uri("Top5Config.xaml", UriKind.Relative));
                    break;
                case "Fav 5":
                    this.PageFrame.Navigate(new Uri("Fav5Config.xaml", UriKind.Relative));
                    break;
                case "Desktop":
                    this.PageFrame.Navigate(new Uri("DesktopContacts.xaml", UriKind.Relative));
                    break;
                case "Version":
                    this.PageFrame.Navigate(new Uri("Version.xaml", UriKind.Relative));
                    break;
            }
        }
    }
}